<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** 初始化 */
require_once 'init.php';

//判断是否登录
if(!$user_id = is_login()){
 	header("Location:" . $config['site_url'] . '/login.php');
	exit;
}

//页面提交处理
if(isset($_POST['Submit'])){
	$oldpassword = trim($_POST['oldpassword']);
	$newpassword = trim($_POST['newpassword']);
	if(!empty($oldpassword) && !empty($newpassword) && $newpassword!=$oldpassword){
		include_logic('user');
		if(!user_find_one(array('password'=>$oldpassword))){
			header("Location:" . $config['site_url'] . '/editprofile.php');
		}else{
			user_update(array('_id'=>new MongoId($user_id)),array('$set'=>array('password'=>$newpassword)));
			header("Location:" . $config['site_url'] . '/logout.php');
		}
		exit;
	}
}

$_GLOBAL['page_title'] = 'Edit Profile';

//载入修改信息页面
include_template('editprofile');